home *** CD-ROM | disk | FTP | other *** search
- 4D<->Resources Externals
- by Robert Hess
- ⌐1992, ENDPOINT! Marketing Information Systems
- Sunnyvale, CA (408)╩733╨4908
- AppleLink: ENDPOINT
- CIS: 71641,1376
- Internet: endpoint@applelink.apple.com or rhessjr@west.darkside.com or
- rhessjr@aol.com
- America Online: RHessJr
- QM-to-QM: Robert Hess, (408) 738-0830 (1200 baud)
-
- Legalese BS From Hell
- =====================
- These externals may not be used in any way in any commercial or for-profit
- database/program/endeavor without the written consent of ENDPOINT!. The author
- does not warranty these externals in any way, nor does ENDPOINT!; use them at
- your own risk. The externals may be redistributed only as a united pair and
- only when included with this documentation file. The externals may not be
- included as a part of any collection of software including (but not restricted
- to only) collections of shareware/freeware/demoware/etc. for which a charge is
- applied without previous written consent of the author. The only exception
- which requires no previous written consent is distribution via America Online,
- CompuServe, GEnie, BIX, Internet, AppleLink, private BBSes or other
- telecommunicative services which charge only for online time but not for
- individual pieces of collections of software.
-
- Not with that garbage out of the way...
-
-
- The included PROC.EXTs contain two externals: 4DtoResource and Resourceto4D.
- They accomplish opposing (complimentary?) functions. 4DtoResource takes a 4D
- variable and copies its contents into a resource file (actually, into a file╒s
- resource fork as a valid resource); Resourceto4D copies the contents of a
- resource in a file╒s resource fork and passes it into a 4D text variable.
-
- ------------------
- Resourceto4D(&T;&S;&I;&S;&T):I
- &T=Pathname to the file to be opened for resource reading
- &S=four-character resource type to be opened
- &I=resource ID to be opened
- &S=resource Name to be opened
- &T=the variable which will be filled with the read resource╒s data
-
- Example 1:
- C_TEXT(gData)
- C_INTEGER(error)
- error:=0
- gData:=""
- error:=Resourceto4D("D80:TestFile";"DATA";128;"";gData)
-
- After execution, the variable ╥gData╙ would contain the contents of resource
- DATA #128 (which has no name) contained in the file ╥TestFile╙ on volume
- ╥HD80╙.
-
- The path may include imbedded folders but may not exceed 255 characters. If
- you exceed 255 characters, I will return an error -193 (╥Resource File Not
- Found╙) to you. The path may not end in a colon; this would indicate that I
- should open the resource fork of a folder. Bad idea.
-
- The four-character type may be anything you wish, which is the whole idea,
- allowing the access to custom resources designed and added by the programmer.
- Passing more than four characters isn╒t advised.
-
- The resource ID must be an integer, obviously. Even if you want to access ID
- zero, you should declare this as equal to ╥0╙.
-
- The name may be passed as Null ("") to indicate a resource without a name.
- NAME TAKES PRECEDENCE. In other words, if you call
- Resourceto4D($myFile;"DATA";128;"Stimpy";gData), I will go looking for a
- resource of type DATA with the name ╥Stimpy╙; I will ignore the resource ID
- number 128. If you pass a name, therefore, it really doesn╒t matter what you
- put in the third parameter (pass a zero, for example).
-
- The final parameter must be of type Text. I will pass the data from the
- resource directly back to you unaffected; it╒s up to you to decide what to do
- with it. You should declare this variable as blank/null/empty prior to calling
- the external. Since a resource cannot exceed 32K, a text resource should
- always be able to handle any resource.
-
- ------------------
- 4DtoResource(&T;&S;&I;&S;&T):I
-
- Example 2:
- C_TEXT(gData)
- C_INTEGER(error)
- error:=0
- gData:="myDATAisBETTERthanYOURdata"
- error:=Resourceto4D("HD80:TestFile";"DATA";128;"MyResource";gData)
-
- All parameters are the same except that the final Text variable should contain
- the data which you wish to have written into the specified resource. You may
- pass an empty string; this will save the resource type specified, but as
- empty.
-
- Additionally, whereas the fourth parameter is highly important in
- Resourceto4D, it is entirely optional in 4DtoResource. This is because I save
- the resource type and ID (which are mandatory), and then toss the resource
- name onto the saved resource. It may be passed as Null ("") if you don╒t care
- to name the resource. Remember: there╒s nothing to stop you from saving
- several resources with the same resource name; it╒s a lousy idea for you to do
- it (because it makes accessing them by name unreliable), but I let you do it.
-
- If you specify an existing resource type and ID, it will be completely
- overwritten. In fact, prior to saving the resource you specify, I delete any
- existing resource with that type and ID/name (whether or not I should save the
- new resource under a unique ID, delete the original and then renumber the new
- copy is debatable; it╒s more time-consuming and, practically, no safer since
- you would have to stop what you were doing and fix the problem prior to using
- the file...not something you would commonly be able to do from within 4D).
-
- You may pass literal data in place of gData above but I don╒t suggest it since
- it╒s more likely that 4D will properly coerce it if you have compiler-directed
- the variable to text.
-
- Trivia Note: why are the externals called what they are? I originally wanted
- to call them ╥GetResource╙ and ╥PutResource╙ or ╥ReadResource╙ and
- ╥WriteResource╙. Unfortunately, ╥GetResource╙ and ╥WriteResource╙ are reserved
- names (why the heck did one from each pair get chosen? You╒ve got me╔Apple
- programmers are a Mountain Dew drunk lot╔) and pairing ╥PutResource╙ with
- ╥ReadResource╙ seemed awkward; so ╥4DtoResource╙ and ╥Resourceto4D╙ were
- born╔Actually, in C, having a procedure named with a number as its first
- character is a no-no, so it╒s really called ╥FourDtoResource"╔I╒m going to
- bed╔
-
- Note: When you pass me the pathname, I open that file (if it exists), access
- it and close it. Therefore, those of you using my externals and hoping that I
- leave the file open should not assume this; I restore the current resource
- file to what it was prior to your calling the externals. (If that doesn╒t make
- sense to you, don╒t worry about it. Only programmer geeks care about it. ;)
-
- So, what do I want for this? NADA. Not a darn thing. Well, OK, you can do two
- things:
-
- 1) Write me a letter (electronically, preferably) or call me and tell me what
- you╒r doing with the external...or, better yet, what other cool stuff you╒d
- like to see me do. (I╒m one of those sick fools who hears, ╥Wouldn╒t it be
- cool if...╙ and ends up spending the next three weeks doing it.
-
- 2) Get involved in the leadership of this country. VOTE, damn it. Or, even
- better, run for office. The more level-headed, reality-based, non-professional
- politicians we have, the more likely I╒ll have a decent world in which to
- raise my kids. Then again, knowing what most 4D users are like, maybe we
- should stay out of politics...
-
- (OK, I lied...there are two materialistic things I╒d like. If you happen to
- own an original cell of Ren & Stimpy, I╒d love it. Or you could pay for me to
- take a C class to become a better programmer. I╒d even name these externals
- after you. Just think: people worldwide would be calling
- ╥Resourceto4DSylvesterAnderson╙, cursing both of us for the stupid external
- name. ;)
-
-
- Version History:
- ----------------
- 0.0.1: Initial ╥release╙.
-
-
- 0.0.2: BUG FIX: There was a bug in 4DtoResource 0.0.1 whereby the saving of a
- non-existant resource failed (in other words, if you did a
- 4DtoResource(╙HD80:File╙;╙DATA╙;128;gData) and DATA #128 didn╒t already exist
- in HD80:File, the resource would not be created. This works now. I have
- properly berated myself...
-
- NEW FEATURE: You have access to resource names now. RE-READ THE DOCS IF YOU
- HAVEN╒T ALREADY! I changed the way that you must call the externals from 0.0.1
- to support resource names.
-
-
- 1.0.0: I do a better FlushVol now. First "release" version.
-
-
- 1.0.1: If you tried to save a resource to a non-existant file (or an existant
- one which had no resource fork), you got an error. No longer.